<template>
    <ShopPageHead></ShopPageHead>
    <main class="index_main" id="all_vue">
        <HomeAdvertising :imgurl="adImg1"></HomeAdvertising>
        <ShopSubMenu2></ShopSubMenu2>
        
        <div class="breadcrumb_box pc_none">
            
                <span class=" ">当前位置：</span>
 
                <NuxtLink
                    :to="`/xiangcunshangcheng/index.html`"
                    class=" "
                    >
                    乡村商城
                </NuxtLink>
                <span class=" ">&gt;</span>

                <NuxtLink
                    :to="`/xiangcunshangcheng/search/search`"
                >
                    搜索
                </NuxtLink>
                <span class=" ">&gt;</span>

                <span class=" "> 供应</span>

        </div>

        <div class="categ_crumb_box clearfix_2">
            <div class="categ_crumb_left phone_none">
                <span class="categ_crumb_left_a" title=""> 当前位置： </span>
                <NuxtLink
                    :to="`/xiangcunshangcheng/index.html`"
                    class="categ_crumb_left_a"
                >
                    乡村商城
                </NuxtLink>
                &gt;
                <NuxtLink
                    :to="`/xiangcunshangcheng/search/search`"
                    class="categ_crumb_left_a"
                >
                    搜索
                </NuxtLink>
                &gt;
                <span class="categ_crumb_left_text">供应</span>
            </div>
        </div>
        <!-- 供应信息列表 -->
        <div class=" clearfix">
            <div class="categ_1_index clearfix">
                <div class="categ_head_box clearfix_2">
                    <a class="categ_head_a" href="" title="">供应信息列表</a>

                    <div class="search_head_text_box phone_none">
                        搜索到有关的供应信息：共 
                        <span class="search_head_text_red">{{total}}</span>
                        条
                    </div>

                    <div class="search_head_text_box pc_none">
                        搜索到共<span class="search_head_text_red">{{total}}</span>条
                    </div>

                </div>
                <div class="categ_table clearfix">
                    <div class="categ_table_head_box">
                        <div class="categ_table_td_1">产品图片</div>
                        <div class="categ_table_td_2">供求信息/公司</div>
                        <div class="categ_table_td_3">发布时间</div>
                        <div class="categ_table_td_4">地区</div>
                    </div>
                    <div class="categ_table_li" v-for="item in pageDataType1">
                        <NuxtLink
                            :to="getShopPathDetail1(item)"
                            class="categ_table_li_a"
                            :title="item.name"
                        >
                            <div class="categ_table_td_1">
                                <img class="categ_table_td_1_img" :src="item.imgurl" :alt="item.name">
                            </div>
                            <div class="search_table_td_2 ">
                                <div class="search_table_td_2_in clearfix">
                                    <div class="search_table_td_2_head dot1">
                                        {{ item.name }}
                                    </div>
                                    <div class="search_table_td_2_dot2 dot2">
                                        {{ item.description }}
                                    </div>
                                </div>
                            </div>
                            <div class="categ_table_td_3">{{ getTime(item.created_at, 'year', 1) }}</div>
                            <div class="categ_table_td_4 dot1">{{ item.city_name }}</div>
                        </NuxtLink>
                    </div>
                </div>
            </div>

            <!-- 分页器 -->
            <div class="pagination page_phone_none" v-if="total">
                <el-pagination 
                    size="small" 
                    background layout="prev, pager, next" 
                    :total="total"
                    v-model:page-size="pageSize" 
                    prev-text="上一页" 
                    next-text="下一页" 
                    :current-page="pageNum"
                    @current-change="changePage" 
                />
            </div>


            
            <div class="pagination page_pc_none" v-if="total">

                <el-pagination 
                    pager-count="5"    
                    size="small" 
                    background 
                    layout=" pager " 
                    :total="total" 
                    class="mt-4"
                    v-model:page-size="pageSize" 
                    :current-page="pageNum" 
                        
                    @current-change="changePage" />
            </div>
        </div>
        <ShopHotNews></ShopHotNews>
    </main>
    <!-- 页面底部 -->
    <HomeFoot></HomeFoot>
</template>

<script setup>
//1.页面必备方法 start ---------------------------------------->
import { ref, onMounted,watch } from 'vue'
import { ElMessage,ElPagination } from 'element-plus'

//分页
let pageNum = ref(1);
let pageSize = ref(10);
let total = ref(0);

let changePage = (value) => {
    console.log("当前页码", value);
    navigateTo(`/xiangcunshangcheng/search/gongying/list-${value}.html`)
}
//1.页面必备方法 end ---------------------------------------->

//2.页面路径 start ---------------------------------------->
//2.1 获得页面数据id
const route = useRoute();
const router = useRouter()
//2.4 获得cityid
const cityId = ref(route.query.cityid)
//2.5 获得keyword
const keyword = ref(route.query.keyword)
//2.页面路径 end ---------------------------------------->


//4.搜索 start ---------------------------------------->
//4.2 页面展示的数据
const pageDataType1 = ref([]);//供应数据
//const pageDataType2 = ref([]);//求购数据 此页面不需要求购数据

//4.3 发起搜索
const pageSearch = async () => {
    let params = {
        catid:346,//栏目id
        city_id:"",//城市id
        keyword:keyword,//搜索关键词 
        page:1,
        pageSize:10,
        type_id:1
    }

    if(keyword.value == undefined || keyword.value == '' || keyword.value == 'NaN'){
        //删除变量params中的city_id参数
        delete params.keyword
    }else{
        params.keyword = keyword.value
    }

    if(cityId.value == undefined || cityId.value == '' || cityId.value == 'NaN'){
        //删除变量params中的city_id参数
        delete params.city_id
    }else{
        params.city_id = parseFloat(cityId.value)
    }

    const pageData = await requestDataPromise('/web/getWebsiteshopList', {
        method: 'GET',
        query: params,
    });

    if (pageData.code == 200) {
        pageDataType1.value = pageData.data.type1;
        total.value = pageData.data.type1_count;
    } else {
        console.log("错误位置：获得该页面数据失败！")
    }
    //开始请求数据
    console.log(params)
    console.log(pageData)
}
//页面初始化的时候调用一下搜索
pageSearch();

//4.4 每次路由一变化就重新请求数据
//4.4.1 监听cityid
watch(() => route.query.cityid, (newVal, oldVal) => {
    if(newVal != undefined){
        cityId.value = parseFloat(newVal)
    }else{
        cityList.value = []
    }
    pageSearch()
})
//4.搜索 end ---------------------------------------->

//5.广告 start ---------------------------------------->
//获得所有广告
let adImg1 = ref({})
onMounted(async () => {
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //从客户端启动广告
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=xcw_shopsearch_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];
})
//5.广告 end ---------------------------------------->

//6.设置seo信息 start---------------------------------------->
//获得当前的完整路径
const fullPath = route.path;
//拆分，取出来中间这一段，然后提取数字部分
const segments = fullPath.split('/');
const targetSegment = segments[1];
const articleId = ref(0);

//通过导航路径反向查询导航id
const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
if (getRouteId.code == 200) {
    articleId.value = getRouteId.data.category_id
} else {
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    console.log("错误位置：通过url路径查询导航池id")
    console.log("后端错误反馈：", getRouteId.message)
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
}
//6.1 设置seo信息
const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
    method: 'GET',
    query: {
        'catid': articleId.value
    },
});

if (setData.code == 200) {
    let seoTitle = setData.data.seo_title;
    let seoDescription = setData.data.seo_description;
    let seoKeywords = setData.data.seo_keywords;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_搜索_供应_" + seoName + "_" + seoSuffix,
        meta: [
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'viewport', content:"width=device-width,initial-scale=1,user-scalable=no"}

        ]
    });
} else {
    // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    // console.log("错误位置：设置列表页面SEO数据")
    // console.log("后端错误反馈：", setData.message)
    // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
}
//6.设置seo信息 end---------------------------------------->
</script>


<style lang="less" scoped>
@import '@/assets/css/shop/list.less';
</style>


<style lang="less" scoped>

 
    @media screen and (min-width:801px){/*pc*/
         
                
            .page_pc_none{display:none!important;}
            .pc_none{display:none;}
    }
    @media screen and (max-width:800px){/*ipad_phone*/
            .index_main{width:100%;margin:0px auto;}
  
            .breadcrumb_box{

                    height:22px;width:100%;margin:10px auto;
                    word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
                    width:92%;
                    font-size:14px;
                    color:#666;  
                    
                    *{
                        font-size:14px;
                        
                        display:inline ;
                        color:#666;  
                        line-height:22px;height:22px;
                        margin-right:5px;
                    }

                }

                .categ_crumb_right{width:92%;margin:0px auto 11px;float:none;display:none;}
                .categ_crumb_panel{width:92%;left:4%;}
                .categ_grey_box{width:92%;margin:10px auto;display:none;}
            
                .categ_1_index{margin:0px auto;width:92%;}
                .categ_head_box{padding-bottom:10px;}
                .categ_head_box .categ_head_a{font-size:16px;}
                .categ_head_box .categ_head_a_more{font-size:12px;}                 



                .categ_table_li{
                    height:auto;padding:10px 0px;overflow:hidden;
                     
 

                    a{display:block;overflow:hidden;}
                    .categ_table_td_1{height:33vw;width:33vw;margin-right:0px; } 
                    .categ_table_td_1_img{width:100%;height:100%;}
                    .search_table_td_2{width:55vw; margin-right:0;float:right;height:auto;}
                    .search_table_td_2_in{width:100%;display:block;vertical-align:top;height:auto;}
                    .search_table_td_2_head{width:100%;margin-top:8px;}
                    .search_table_td_2_dot2{width:100%;margin-bottom:8px;-webkit-line-clamp:1;height:18px;}
                    .search_table_td_2_dot3{width:100%;-webkit-line-clamp:1;}

                    .categ_table_td_3{
                            float:left;text-align:right;width:auto;line-height:22px;height:22px;margin:0 4vw;font-size:14px;
                            border:solid 1px #E9E9E9;
                            padding:0px 4px;        
                        }
                    .categ_table_td_4{
                            padding:0px 4px;        
                            border:solid 1px #E9E9E9;
                        height:22px;line-height:22px;float:left;text-align:right;width:auto;font-size:14px; 
                    }

                }
                .categ_crumb_box{padding:0;margin:0;}        

                .phone_categ_crumb_out{
                     
                    width:92%;margin:0px auto 8px;position:relative;
                }

                .categ_crumb_city{
                        padding:0px 10px;border-radius:8px;
                        background:rgba(160,28,14,.1);
                        
                        float:left; 
                         
                        .categ_crumb_right_text{float: left;
                            height: 21px;
                            line-height: 21px;
                            color: #333;margin-right:4px;
                            font-size: 14px;
                        }

                        .categ_crumb_right_btn{
                            float: left;
                            height: 11px;width:11px;
                            margin:4px 0px 0px 5px;
                             
                               background-image:url(../../../public/image/9.png);                           
                        }
                        .categ_crumb_right_btn_pull{
                             background-image:url(../../../public/image/10.png);                           
                        }

                        .phone_categ_crumb_city_panel{
                            position:absolute;top:122%;right:0px; 
                             border:solid 1px #A01C0E;background:#fff;
                            width:100%;overflow:auto;height:440px;z-index: 111;
                        }
                        .phone_categ_crumb_city_panel_span{
                            display:block;padding:6px 4px;
                            color:#333;font-size:14px;line-height:18px;
                        }
                        .phone_categ_crumb_city_panel_span_only{
                             
                            color:#A01C0E;font-weight:bold;
                        }


                }   

                .phone_categ_crumb_zone{
                       margin-left:8px;float:right;
                        padding:0px 10px;border-radius:8px;
                        background:rgba(160,28,14,.1);
                        
                        .phone_categ_crumb_zone_text{
                            float:left;line-height:21px;height:21px;color:#333;font-size:14px;

                        }
                    .phone_categ_crumb_zone_btn{
                        float:right;
                        height:11px;width:11px;
                        margin:4px 0px 0px 5px;
                         
                           background-image:url(../../../public/image/9.png);                           
                    }
                    .phone_categ_crumb_zone_btn_pull{
                           background-image:url(../../../public/image/10.png);                           
                    }
                     

                        .phone_categ_crumb_zone_panel{
                            position:absolute;top:122%;right:0px;
                            border:solid 1px #A01C0E;
                             background:#fff;z-index: 111;
                            width:100%;height:440px;overflow:auto;


                        }
                        .phone_categ_crumb_zone_panel_span{
                            display:block;padding:6px 4px;
                            color:#333;font-size:14px;line-height:18px;
                        }

                        .phone_categ_crumb_zone_panel_span_only{
                            font-weight:bold;color:#A01C0E;
                        }

                }
                .pagination{margin:25px auto 0px;}
                 
                 
                .pagination /deep/.el-pagination.is-background .el-pager li{margin:0px 4px;}

                .phone_categ_crumb_out::after{content: '';display: block;height: 0;visibility: hidden;clear: both;}
                .page_phone_none{display:none!important;}
                .pc_categ_crumb_panel_none{    display:none!important; }
                .categ_table_head_box{display:none;} 

                .phone_none{display:none;}
    }

</style>



